package c.j.a.d.b.j;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Handler;
import android.os.Handler.Callback;
import android.os.Looper;
import android.os.Message;
import android.text.TextUtils;
import android.util.SparseArray;
import c.j.a.d.b.a.a.b;
import c.j.a.d.b.a.a.c;
import c.j.a.d.b.b.e;
import org.json.JSONObject;

/* compiled from: RetryScheduler */
public class a0 implements Callback, b {
    public static volatile a0 h;
    public final Context a = c.j.a.d.b.e.b.a();
    public final Handler b = new Handler(Looper.getMainLooper(), this);
    public final SparseArray<a> c = new SparseArray();
    public final boolean d;
    public long e;
    public int f = 0;
    public ConnectivityManager g;

    /* compiled from: RetryScheduler */
    public static class a {
        public final int a;
        public final int b;
        public final int c;
        public final int d;
        public final int e;
        public final boolean f;
        public final int[] g;
        public int h;
        public int i;
        public boolean j;
        public long k;
        public boolean l;

        public a(int i, int i2, int i3, int i4, int i5, boolean z, int[] iArr) {
            if (i4 < 20000) {
                i4 = 20000;
            }
            if (i5 < 20000) {
                i5 = 20000;
            }
            this.a = i;
            this.b = i2;
            this.c = i3;
            this.d = i4;
            this.e = i5;
            this.f = z;
            this.g = iArr;
            this.h = i4;
        }

        public synchronized void a() {
            this.h += this.e;
        }
    }

    public a0() {
        if (c.j.a.d.b.l.a.f.b("use_network_callback", 0) == 1) {
            c.j.a.d.b.e.b.q().execute(new x(this));
        }
        this.d = c.j.a.d.b.n.a.M();
        c.a.a(this);
    }

    public static a0 a() {
        if (h == null) {
            synchronized (a0.class) {
                if (h == null) {
                    h = new a0();
                }
            }
        }
        return h;
    }

    /* JADX WARNING: Removed duplicated region for block: B:63:0x0134 A:{SYNTHETIC} */
    /* JADX WARNING: Removed duplicated region for block: B:81:0x017f  */
    /* JADX WARNING: Removed duplicated region for block: B:67:0x013c  */
    /* JADX WARNING: Missing block: B:15:0x002e, code skipped:
            r6 = c.b.a.a.a.h("doSchedulerRetryInSubThread: downloadId = ", r0, ", retryCount = ");
            r6.append(r5.i);
            r6.append(", mWaitingRetryTasksCount = ");
            r6.append(r1.f);
            c.j.a.d.b.g.a.e("RetryScheduler", r6.toString());
            r4 = c.j.a.d.b.e.i.a(r3).k(r0);
     */
    /* JADX WARNING: Missing block: B:16:0x0056, code skipped:
            if (r4 != null) goto L_0x005d;
     */
    /* JADX WARNING: Missing block: B:17:0x0058, code skipped:
            r17.f(r18);
     */
    /* JADX WARNING: Missing block: B:18:0x005d, code skipped:
            r9 = new java.lang.StringBuilder();
            r9.append("doSchedulerRetryInSubThread，id:");
            r9.append(r0);
            c.j.a.d.b.g.a.g("RetryScheduler", r9.toString());
            r6 = r4.p0();
     */
    /* JADX WARNING: Missing block: B:19:0x0078, code skipped:
            if (r6 == -3) goto L_0x01ba;
     */
    /* JADX WARNING: Missing block: B:21:0x007b, code skipped:
            if (r6 != -4) goto L_0x007f;
     */
    /* JADX WARNING: Missing block: B:23:0x0081, code skipped:
            if (r6 == -5) goto L_0x0197;
     */
    /* JADX WARNING: Missing block: B:24:0x0083, code skipped:
            if (r6 != -2) goto L_0x008d;
     */
    /* JADX WARNING: Missing block: B:26:0x0089, code skipped:
            if (r4.h() == false) goto L_0x008d;
     */
    /* JADX WARNING: Missing block: B:28:0x008e, code skipped:
            if (r6 == -1) goto L_0x0092;
     */
    /* JADX WARNING: Missing block: B:29:0x0092, code skipped:
            if (r2 != 0) goto L_0x009a;
     */
    /* JADX WARNING: Missing block: B:31:0x0096, code skipped:
            if (r5.f == false) goto L_?;
     */
    /* JADX WARNING: Missing block: B:32:0x0098, code skipped:
            r0 = null;
     */
    /* JADX WARNING: Missing block: B:33:0x009a, code skipped:
            r0 = 1;
     */
    /* JADX WARNING: Missing block: B:34:0x009b, code skipped:
            r6 = r4.A0;
     */
    /* JADX WARNING: Missing block: B:35:0x009d, code skipped:
            if (r0 == null) goto L_0x0133;
     */
    /* JADX WARNING: Missing block: B:37:0x00a3, code skipped:
            if (c.j.a.d.b.n.a.W(r6) == false) goto L_0x0133;
     */
    /* JADX WARNING: Missing block: B:40:?, code skipped:
            r11 = c.j.a.d.b.n.a.J(r4.k0());
     */
    /* JADX WARNING: Missing block: B:41:0x00b0, code skipped:
            r0 = move-exception;
     */
    /* JADX WARNING: Missing block: B:42:0x00b1, code skipped:
            r0.printStackTrace();
            r11 = 0;
     */
    /* JADX WARNING: Missing block: B:59:0x012e, code skipped:
            if (r0.b("download_when_space_negative", 0) != 1) goto L_0x0130;
     */
    /* JADX WARNING: Missing block: B:92:0x0197, code skipped:
            if (r6 != -2) goto L_0x01a6;
     */
    /* JADX WARNING: Missing block: B:93:0x0199, code skipped:
            java.util.Objects.requireNonNull(c.j.a.d.b.e.i.a(c.j.a.d.b.e.b.a()));
            r2 = c.j.a.d.b.e.b.a;
     */
    /* JADX WARNING: Missing block: B:94:0x01a6, code skipped:
            r2 = c.j.a.d.b.e.b.w();
     */
    /* JADX WARNING: Missing block: B:95:0x01aa, code skipped:
            if (r2 == null) goto L_0x01b6;
     */
    /* JADX WARNING: Missing block: B:96:0x01ac, code skipped:
            ((c.j.a.d.a.i.c) r2).c(java.util.Collections.singletonList(r4), 3);
     */
    /* JADX WARNING: Missing block: B:97:0x01b6, code skipped:
            r17.f(r18);
     */
    /* JADX WARNING: Missing block: B:98:0x01ba, code skipped:
            r17.f(r18);
     */
    /* JADX WARNING: Missing block: B:106:?, code skipped:
            return;
     */
    /* JADX WARNING: Missing block: B:108:?, code skipped:
            return;
     */
    /* JADX WARNING: Missing block: B:109:?, code skipped:
            return;
     */
    /* JADX WARNING: Missing block: B:113:?, code skipped:
            return;
     */
    /* JADX WARNING: Missing block: B:115:?, code skipped:
            return;
     */
    public static void e(c.j.a.d.b.j.a0 r17, int r18, int r19, boolean r20) {
        /*
        r1 = r17;
        r0 = r18;
        r2 = r19;
        r3 = r1.a;
        if (r3 != 0) goto L_0x000c;
    L_0x000a:
        goto L_0x01bd;
    L_0x000c:
        r4 = r1.c;
        monitor-enter(r4);
        r5 = r1.c;	 Catch:{ all -> 0x01be }
        r5 = r5.get(r0);	 Catch:{ all -> 0x01be }
        r5 = (c.j.a.d.b.j.a0.a) r5;	 Catch:{ all -> 0x01be }
        if (r5 != 0) goto L_0x001c;
    L_0x0019:
        monitor-exit(r4);	 Catch:{ all -> 0x01be }
        goto L_0x01bd;
    L_0x001c:
        r6 = r5.l;	 Catch:{ all -> 0x01be }
        r7 = 1;
        r8 = 0;
        if (r6 == 0) goto L_0x002d;
    L_0x0022:
        r5.l = r8;	 Catch:{ all -> 0x01be }
        r6 = r1.f;	 Catch:{ all -> 0x01be }
        r6 = r6 - r7;
        r1.f = r6;	 Catch:{ all -> 0x01be }
        if (r6 >= 0) goto L_0x002d;
    L_0x002b:
        r1.f = r8;	 Catch:{ all -> 0x01be }
    L_0x002d:
        monitor-exit(r4);	 Catch:{ all -> 0x01be }
        r4 = "RetryScheduler";
        r6 = "doSchedulerRetryInSubThread: downloadId = ";
        r9 = ", retryCount = ";
        r6 = c.b.a.a.a.h(r6, r0, r9);
        r9 = r5.i;
        r6.append(r9);
        r9 = ", mWaitingRetryTasksCount = ";
        r6.append(r9);
        r9 = r1.f;
        r6.append(r9);
        r6 = r6.toString();
        c.j.a.d.b.g.a.e(r4, r6);
        r4 = c.j.a.d.b.e.i.a(r3);
        r4 = r4.k(r0);
        if (r4 != 0) goto L_0x005d;
    L_0x0058:
        r17.f(r18);
        goto L_0x01bd;
    L_0x005d:
        r6 = "RetryScheduler";
        r9 = new java.lang.StringBuilder;
        r9.<init>();
        r10 = "doSchedulerRetryInSubThread，id:";
        r9.append(r10);
        r9.append(r0);
        r9 = r9.toString();
        c.j.a.d.b.g.a.g(r6, r9);
        r6 = r4.p0();
        r9 = -3;
        if (r6 == r9) goto L_0x01ba;
    L_0x007a:
        r9 = -4;
        if (r6 != r9) goto L_0x007f;
    L_0x007d:
        goto L_0x01ba;
    L_0x007f:
        r9 = -5;
        r10 = -2;
        if (r6 == r9) goto L_0x0197;
    L_0x0083:
        if (r6 != r10) goto L_0x008d;
    L_0x0085:
        r9 = r4.h();
        if (r9 == 0) goto L_0x008d;
    L_0x008b:
        goto L_0x0197;
    L_0x008d:
        r0 = -1;
        if (r6 == r0) goto L_0x0092;
    L_0x0090:
        goto L_0x01bd;
    L_0x0092:
        if (r2 != 0) goto L_0x009a;
    L_0x0094:
        r0 = r5.f;
        if (r0 == 0) goto L_0x01bd;
    L_0x0098:
        r0 = 0;
        goto L_0x009b;
    L_0x009a:
        r0 = 1;
    L_0x009b:
        r6 = r4.A0;
        if (r0 == 0) goto L_0x0133;
    L_0x009f:
        r9 = c.j.a.d.b.n.a.W(r6);
        if (r9 == 0) goto L_0x0133;
    L_0x00a5:
        r9 = 0;
        r0 = r4.k0();	 Catch:{ a -> 0x00b0 }
        r11 = c.j.a.d.b.n.a.J(r0);	 Catch:{ a -> 0x00b0 }
        goto L_0x00b5;
    L_0x00b0:
        r0 = move-exception;
        r0.printStackTrace();
        r11 = r9;
    L_0x00b5:
        r0 = r6 instanceof com.ss.android.socialbase.downloader.e.e;
        if (r0 == 0) goto L_0x00be;
    L_0x00b9:
        r6 = (com.ss.android.socialbase.downloader.e.e) r6;
        r13 = r6.d;
        goto L_0x00c5;
    L_0x00be:
        r13 = r4.T;
        r15 = r4.I();
        r13 = r13 - r15;
    L_0x00c5:
        r0 = (r11 > r13 ? 1 : (r11 == r13 ? 0 : -1));
        if (r0 >= 0) goto L_0x0132;
    L_0x00c9:
        r0 = r4.g0();
        r0 = c.j.a.d.b.l.a.d(r0);
        r6 = "space_fill_part_download";
        r6 = r0.b(r6, r8);
        if (r6 != r7) goto L_0x0130;
    L_0x00d9:
        r6 = (r11 > r9 ? 1 : (r11 == r9 ? 0 : -1));
        if (r6 <= 0) goto L_0x0128;
    L_0x00dd:
        r6 = 100;
        r8 = "space_fill_min_keep_mb";
        r0 = r0.b(r8, r6);
        if (r0 <= 0) goto L_0x0132;
    L_0x00e7:
        r13 = (long) r0;
        r15 = 1048576; // 0x100000 float:1.469368E-39 double:5.180654E-318;
        r13 = r13 * r15;
        r13 = r11 - r13;
        r6 = "retry schedule: available = ";
        r6 = c.b.a.a.a.g(r6);
        r11 = c.j.a.d.b.n.a.a(r11);
        r6.append(r11);
        r8 = "MB, minKeep = ";
        r6.append(r8);
        r6.append(r0);
        r0 = "MB, canDownload = ";
        r6.append(r0);
        r11 = c.j.a.d.b.n.a.a(r13);
        r6.append(r11);
        r0 = "MB";
        r6.append(r0);
        r0 = r6.toString();
        r6 = "RetryScheduler";
        c.j.a.d.b.g.a.e(r6, r0);
        r0 = (r13 > r9 ? 1 : (r13 == r9 ? 0 : -1));
        if (r0 > 0) goto L_0x0132;
    L_0x0122:
        r0 = "doSchedulerRetryInSubThread: canDownload <= 0 , canRetry = false !!!!";
        c.j.a.d.b.g.a.f(r6, r0);
        goto L_0x0130;
    L_0x0128:
        r6 = "download_when_space_negative";
        r0 = r0.b(r6, r8);
        if (r0 == r7) goto L_0x0132;
    L_0x0130:
        r0 = 0;
        goto L_0x0133;
    L_0x0132:
        r0 = 1;
    L_0x0133:
        monitor-enter(r5);
        r6 = r5.i;	 Catch:{ all -> 0x0194 }
        r6 = r6 + r7;
        r5.i = r6;	 Catch:{ all -> 0x0194 }
        monitor-exit(r5);
        if (r0 == 0) goto L_0x017f;
    L_0x013c:
        r0 = "RetryScheduler";
        r1 = "doSchedulerRetry: restart task, ****** id = ";
        r1 = c.b.a.a.a.g(r1);
        r2 = r5.a;
        r1.append(r2);
        r1 = r1.toString();
        c.j.a.d.b.g.a.e(r0, r1);
        r0 = java.lang.System.currentTimeMillis();
        monitor-enter(r5);
        r5.k = r0;	 Catch:{ all -> 0x017b }
        monitor-exit(r5);
        if (r20 == 0) goto L_0x015d;
    L_0x015a:
        r5.a();
    L_0x015d:
        r0 = r5.i;
        r0 = java.lang.Integer.valueOf(r0);
        r1 = "retry_schedule_count";
        r4.t(r1, r0);
        r0 = r4.o0();
        r1 = -1;
        if (r0 != r1) goto L_0x01bd;
    L_0x016f:
        r0 = c.j.a.d.b.e.i.a(r3);
        r1 = r4.g0();
        r0.j(r1);
        goto L_0x01bd;
    L_0x017b:
        r0 = move-exception;
        r1 = r0;
        monitor-exit(r5);
        throw r1;
    L_0x017f:
        if (r20 == 0) goto L_0x0184;
    L_0x0181:
        r5.a();
    L_0x0184:
        r0 = r4.g;
        if (r0 != 0) goto L_0x0190;
    L_0x0188:
        r0 = r4.h();
        if (r0 == 0) goto L_0x018f;
    L_0x018e:
        goto L_0x0190;
    L_0x018f:
        r7 = 0;
    L_0x0190:
        r1.d(r4, r7, r2);
        goto L_0x01bd;
    L_0x0194:
        r0 = move-exception;
        monitor-exit(r5);
        throw r0;
    L_0x0197:
        if (r6 != r10) goto L_0x01a6;
    L_0x0199:
        r2 = c.j.a.d.b.e.b.a();
        r2 = c.j.a.d.b.e.i.a(r2);
        java.util.Objects.requireNonNull(r2);
        r2 = c.j.a.d.b.e.b.a;
    L_0x01a6:
        r2 = c.j.a.d.b.e.b.w();
        if (r2 == 0) goto L_0x01b6;
    L_0x01ac:
        r3 = java.util.Collections.singletonList(r4);
        r4 = 3;
        r2 = (c.j.a.d.a.i.c) r2;
        r2.c(r3, r4);
    L_0x01b6:
        r17.f(r18);
        goto L_0x01bd;
    L_0x01ba:
        r17.f(r18);
    L_0x01bd:
        return;
    L_0x01be:
        r0 = move-exception;
        monitor-exit(r4);	 Catch:{ all -> 0x01be }
        throw r0;
        */
        throw new UnsupportedOperationException("Method not decompiled: c.j.a.d.b.j.a0.e(c.j.a.d.b.j.a0, int, int, boolean):void");
    }

    /* JADX WARNING: Missing block: B:13:0x001b, code skipped:
            r1 = new java.lang.StringBuilder();
            r1.append("scheduleAllTaskRetry, level = [");
            r1.append(r8);
            r1.append("], force = [");
            r1.append(r9);
            r1.append("]");
            c.j.a.d.b.g.a.e("RetryScheduler", r1.toString());
     */
    /* JADX WARNING: Missing block: B:14:0x003f, code skipped:
            if (r9 == false) goto L_0x0046;
     */
    /* JADX WARNING: Missing block: B:15:0x0041, code skipped:
            r7.b.removeMessages(0);
     */
    /* JADX WARNING: Missing block: B:16:0x0046, code skipped:
            r1 = android.os.Message.obtain();
            r1.what = 0;
            r1.arg1 = r8;
            r1.arg2 = r9;
            r7.b.sendMessageDelayed(r1, 2000);
     */
    /* JADX WARNING: Missing block: B:17:0x0057, code skipped:
            return;
     */
    public final void b(int r8, boolean r9) {
        /*
        r7 = this;
        r0 = r7.f;
        if (r0 > 0) goto L_0x0005;
    L_0x0004:
        return;
    L_0x0005:
        r0 = java.lang.System.currentTimeMillis();
        monitor-enter(r7);
        if (r9 != 0) goto L_0x0018;
    L_0x000c:
        r2 = r7.e;	 Catch:{ all -> 0x0058 }
        r2 = r0 - r2;
        r4 = 20000; // 0x4e20 float:2.8026E-41 double:9.8813E-320;
        r6 = (r2 > r4 ? 1 : (r2 == r4 ? 0 : -1));
        if (r6 >= 0) goto L_0x0018;
    L_0x0016:
        monitor-exit(r7);	 Catch:{ all -> 0x0058 }
        return;
    L_0x0018:
        r7.e = r0;	 Catch:{ all -> 0x0058 }
        monitor-exit(r7);	 Catch:{ all -> 0x0058 }
        r0 = "RetryScheduler";
        r1 = new java.lang.StringBuilder;
        r1.<init>();
        r2 = "scheduleAllTaskRetry, level = [";
        r1.append(r2);
        r1.append(r8);
        r2 = "], force = [";
        r1.append(r2);
        r1.append(r9);
        r2 = "]";
        r1.append(r2);
        r1 = r1.toString();
        c.j.a.d.b.g.a.e(r0, r1);
        r0 = 0;
        if (r9 == 0) goto L_0x0046;
    L_0x0041:
        r1 = r7.b;
        r1.removeMessages(r0);
    L_0x0046:
        r1 = android.os.Message.obtain();
        r1.what = r0;
        r1.arg1 = r8;
        r1.arg2 = r9;
        r8 = r7.b;
        r2 = 2000; // 0x7d0 float:2.803E-42 double:9.88E-321;
        r8.sendMessageDelayed(r1, r2);
        return;
    L_0x0058:
        r8 = move-exception;
        monitor-exit(r7);	 Catch:{ all -> 0x0058 }
        throw r8;
        */
        throw new UnsupportedOperationException("Method not decompiled: c.j.a.d.b.j.a0.b(int, boolean):void");
    }

    public void c(com.ss.android.socialbase.downloader.g.c cVar) {
        if (cVar != null && !TextUtils.isEmpty(e.a) && e.a.equals(cVar.u)) {
            boolean z = cVar.g || cVar.h();
            d(cVar, z, h());
        }
    }

    /* JADX WARNING: Removed duplicated region for block: B:79:0x015e A:{Catch:{ all -> 0x012b, all -> 0x01aa }} */
    /* JADX WARNING: Removed duplicated region for block: B:78:0x015c A:{Catch:{ all -> 0x012b, all -> 0x01aa }} */
    /* JADX WARNING: Removed duplicated region for block: B:82:0x0171 A:{Catch:{ all -> 0x012b, all -> 0x01aa }} */
    /* JADX WARNING: Removed duplicated region for block: B:89:0x0193 A:{Catch:{ all -> 0x012b, all -> 0x01aa }} */
    public final void d(com.ss.android.socialbase.downloader.g.c r12, boolean r13, int r14) {
        /*
        r11 = this;
        r0 = r12.A0;
        if (r0 != 0) goto L_0x0005;
    L_0x0004:
        return;
    L_0x0005:
        r1 = r12.g0();
        r2 = r11.c;
        r2 = r2.get(r1);
        r2 = (c.j.a.d.b.j.a0.a) r2;
        if (r2 != 0) goto L_0x002e;
    L_0x0013:
        r3 = r11.c;
        monitor-enter(r3);
        r2 = r11.c;	 Catch:{ all -> 0x002b }
        r2 = r2.get(r1);	 Catch:{ all -> 0x002b }
        r2 = (c.j.a.d.b.j.a0.a) r2;	 Catch:{ all -> 0x002b }
        if (r2 != 0) goto L_0x0024;
    L_0x0020:
        r2 = r11.g(r1);	 Catch:{ all -> 0x002b }
    L_0x0024:
        r4 = r11.c;	 Catch:{ all -> 0x002b }
        r4.put(r1, r2);	 Catch:{ all -> 0x002b }
        monitor-exit(r3);	 Catch:{ all -> 0x002b }
        goto L_0x002e;
    L_0x002b:
        r12 = move-exception;
        monitor-exit(r3);	 Catch:{ all -> 0x002b }
        throw r12;
    L_0x002e:
        r1 = r2.i;
        r3 = r2.c;
        if (r1 <= r3) goto L_0x005d;
    L_0x0034:
        r12 = "RetryScheduler";
        r13 = "tryStartScheduleRetry, id = ";
        r13 = c.b.a.a.a.g(r13);
        r14 = r2.a;
        r13.append(r14);
        r14 = ", mRetryCount = ";
        r13.append(r14);
        r14 = r2.i;
        r13.append(r14);
        r14 = ", maxCount = ";
        r13.append(r14);
        r14 = r2.c;
        r13.append(r14);
        r13 = r13.toString();
        c.j.a.d.b.g.a.f(r12, r13);
        return;
    L_0x005d:
        r1 = r0.a;
        r3 = c.j.a.d.b.n.a.W(r0);
        r4 = 0;
        r5 = 1;
        if (r3 != 0) goto L_0x00ae;
    L_0x0067:
        r0 = c.j.a.d.b.n.a.X(r0);
        if (r0 != 0) goto L_0x00ae;
    L_0x006d:
        r0 = r12.i();
        if (r0 == 0) goto L_0x0079;
    L_0x0073:
        r0 = r12.h();
        if (r0 != 0) goto L_0x00ae;
    L_0x0079:
        r0 = r2.g;
        if (r0 == 0) goto L_0x008e;
    L_0x007d:
        r3 = r0.length;
        if (r3 != 0) goto L_0x0081;
    L_0x0080:
        goto L_0x008e;
    L_0x0081:
        r3 = r0.length;
        r6 = 0;
    L_0x0083:
        if (r6 >= r3) goto L_0x008e;
    L_0x0085:
        r7 = r0[r6];
        if (r7 != r1) goto L_0x008b;
    L_0x0089:
        r0 = 1;
        goto L_0x008f;
    L_0x008b:
        r6 = r6 + 1;
        goto L_0x0083;
    L_0x008e:
        r0 = 0;
    L_0x008f:
        if (r0 != 0) goto L_0x0092;
    L_0x0091:
        return;
    L_0x0092:
        r0 = "RetryScheduler";
        r3 = "white error code, id = ";
        r3 = c.b.a.a.a.g(r3);
        r6 = r2.a;
        r3.append(r6);
        r6 = ", error code = ";
        r3.append(r6);
        r3.append(r1);
        r1 = r3.toString();
        c.j.a.d.b.g.a.e(r0, r1);
    L_0x00ae:
        r2.j = r13;
        r0 = r11.c;
        monitor-enter(r0);
        r1 = r2.l;	 Catch:{ all -> 0x01e3 }
        if (r1 != 0) goto L_0x00be;
    L_0x00b7:
        r2.l = r5;	 Catch:{ all -> 0x01e3 }
        r1 = r11.f;	 Catch:{ all -> 0x01e3 }
        r1 = r1 + r5;
        r11.f = r1;	 Catch:{ all -> 0x01e3 }
    L_0x00be:
        monitor-exit(r0);	 Catch:{ all -> 0x01e3 }
        r0 = r2.h;
        r1 = "RetryScheduler";
        r3 = "tryStartScheduleRetry: id = ";
        r3 = c.b.a.a.a.g(r3);
        r5 = r2.a;
        r3.append(r5);
        r5 = ", delayTimeMills = ";
        r3.append(r5);
        r3.append(r0);
        r5 = ", mWaitingRetryTasks = ";
        r3.append(r5);
        r5 = r11.f;
        r3.append(r5);
        r3 = r3.toString();
        c.j.a.d.b.g.a.e(r1, r3);
        r1 = r2.f;
        if (r1 == 0) goto L_0x01cc;
    L_0x00eb:
        if (r14 != 0) goto L_0x00f1;
    L_0x00ed:
        r1 = r2.d;
        r2.h = r1;
    L_0x00f1:
        r0 = (long) r0;
        r3 = com.ss.android.socialbase.downloader.impls.RetryJobSchedulerService.a;
        r5 = 0;
        r3 = (r0 > r5 ? 1 : (r0 == r5 ? 0 : -1));
        if (r3 > 0) goto L_0x00fc;
    L_0x00fa:
        goto L_0x01ae;
    L_0x00fc:
        r3 = c.j.a.d.b.e.b.a();
        if (r3 != 0) goto L_0x0104;
    L_0x0102:
        goto L_0x01ae;
    L_0x0104:
        r7 = r12.h();
        if (r7 == 0) goto L_0x0117;
    L_0x010a:
        r7 = c.j.a.d.b.e.b.a();
        r7 = c.j.a.d.b.e.i.a(r7);
        java.util.Objects.requireNonNull(r7);
        r7 = c.j.a.d.b.e.b.a;
    L_0x0117:
        r7 = "jobscheduler";
        r7 = r3.getSystemService(r7);	 Catch:{ all -> 0x01aa }
        r7 = (android.app.job.JobScheduler) r7;	 Catch:{ all -> 0x01aa }
        if (r7 != 0) goto L_0x0123;
    L_0x0121:
        goto L_0x01ae;
    L_0x0123:
        r8 = r12.g0();	 Catch:{ all -> 0x012b }
        r7.cancel(r8);	 Catch:{ all -> 0x012b }
        goto L_0x012f;
    L_0x012b:
        r8 = move-exception;
        r8.printStackTrace();	 Catch:{ all -> 0x01aa }
    L_0x012f:
        r8 = 2;
        if (r14 == 0) goto L_0x013c;
    L_0x0132:
        if (r13 == 0) goto L_0x0137;
    L_0x0134:
        if (r14 == r8) goto L_0x0137;
    L_0x0136:
        goto L_0x013c;
    L_0x0137:
        r5 = 60000; // 0xea60 float:8.4078E-41 double:2.9644E-319;
        r5 = r5 + r0;
        goto L_0x013e;
    L_0x013c:
        r0 = 1000; // 0x3e8 float:1.401E-42 double:4.94E-321;
    L_0x013e:
        r14 = new android.app.job.JobInfo$Builder;	 Catch:{ all -> 0x01aa }
        r8 = r12.g0();	 Catch:{ all -> 0x01aa }
        r9 = new android.content.ComponentName;	 Catch:{ all -> 0x01aa }
        r3 = r3.getPackageName();	 Catch:{ all -> 0x01aa }
        r10 = com.ss.android.socialbase.downloader.impls.RetryJobSchedulerService.class;
        r10 = r10.getName();	 Catch:{ all -> 0x01aa }
        r9.<init>(r3, r10);	 Catch:{ all -> 0x01aa }
        r14.<init>(r8, r9);	 Catch:{ all -> 0x01aa }
        r14 = r14.setMinimumLatency(r0);	 Catch:{ all -> 0x01aa }
        if (r13 == 0) goto L_0x015e;
    L_0x015c:
        r13 = 2;
        goto L_0x015f;
    L_0x015e:
        r13 = 1;
    L_0x015f:
        r13 = r14.setRequiredNetworkType(r13);	 Catch:{ all -> 0x01aa }
        r13 = r13.setRequiresCharging(r4);	 Catch:{ all -> 0x01aa }
        r13 = r13.setRequiresDeviceIdle(r4);	 Catch:{ all -> 0x01aa }
        r0 = 0;
        r14 = (r5 > r0 ? 1 : (r5 == r0 ? 0 : -1));
        if (r14 <= 0) goto L_0x0174;
    L_0x0171:
        r13.setOverrideDeadline(r5);	 Catch:{ all -> 0x01aa }
    L_0x0174:
        r13 = r13.build();	 Catch:{ all -> 0x01aa }
        r13 = r7.schedule(r13);	 Catch:{ all -> 0x01aa }
        if (r13 <= 0) goto L_0x0191;
    L_0x017e:
        r12 = r12.h();	 Catch:{ all -> 0x01aa }
        if (r12 == 0) goto L_0x0191;
    L_0x0184:
        r12 = c.j.a.d.b.e.b.a();	 Catch:{ all -> 0x01aa }
        r12 = c.j.a.d.b.e.i.a(r12);	 Catch:{ all -> 0x01aa }
        java.util.Objects.requireNonNull(r12);	 Catch:{ all -> 0x01aa }
        r12 = c.j.a.d.b.e.b.a;	 Catch:{ all -> 0x01aa }
    L_0x0191:
        if (r13 > 0) goto L_0x01ae;
    L_0x0193:
        r12 = "RetrySchedulerService";
        r14 = new java.lang.StringBuilder;	 Catch:{ all -> 0x01aa }
        r14.<init>();	 Catch:{ all -> 0x01aa }
        r0 = "schedule err errCode = ";
        r14.append(r0);	 Catch:{ all -> 0x01aa }
        r14.append(r13);	 Catch:{ all -> 0x01aa }
        r13 = r14.toString();	 Catch:{ all -> 0x01aa }
        c.j.a.d.b.g.a.f(r12, r13);	 Catch:{ all -> 0x01aa }
        goto L_0x01ae;
    L_0x01aa:
        r12 = move-exception;
        r12.printStackTrace();
    L_0x01ae:
        r12 = r11.d;
        if (r12 == 0) goto L_0x01e2;
    L_0x01b2:
        r12 = java.lang.System.currentTimeMillis();
        monitor-enter(r2);
        r2.k = r12;	 Catch:{ all -> 0x01c9 }
        monitor-exit(r2);
        monitor-enter(r2);
        r12 = r2.i;	 Catch:{ all -> 0x01c6 }
        r12 = r12 + 1;
        r2.i = r12;	 Catch:{ all -> 0x01c6 }
        monitor-exit(r2);
        r2.a();
        goto L_0x01e2;
    L_0x01c6:
        r12 = move-exception;
        monitor-exit(r2);
        throw r12;
    L_0x01c9:
        r12 = move-exception;
        monitor-exit(r2);
        throw r12;
    L_0x01cc:
        if (r13 == 0) goto L_0x01cf;
    L_0x01ce:
        return;
    L_0x01cf:
        r13 = r11.b;
        r14 = r12.g0();
        r13.removeMessages(r14);
        r13 = r11.b;
        r12 = r12.g0();
        r0 = (long) r0;
        r13.sendEmptyMessageDelayed(r12, r0);
    L_0x01e2:
        return;
    L_0x01e3:
        r12 = move-exception;
        monitor-exit(r0);	 Catch:{ all -> 0x01e3 }
        throw r12;
        */
        throw new UnsupportedOperationException("Method not decompiled: c.j.a.d.b.j.a0.d(com.ss.android.socialbase.downloader.g.c, boolean, int):void");
    }

    public final void f(int i) {
        synchronized (this.c) {
            this.c.remove(i);
        }
    }

    public final a g(int i) {
        int optInt;
        int[] iArr;
        int i2;
        boolean z;
        c.j.a.d.b.l.a d = c.j.a.d.b.l.a.d(i);
        int i3 = 0;
        int b = d.b("retry_schedule", 0);
        JSONObject l = d.l("retry_schedule_config");
        int[] iArr2 = null;
        int i4 = 60;
        if (l != null) {
            int optInt2 = l.optInt("max_count", 60);
            optInt = l.optInt("interval_sec", 60);
            i4 = l.optInt("interval_sec_acceleration", 60);
            boolean z2 = true;
            if (l.optInt("use_job_scheduler", 0) != 1) {
                z2 = false;
            }
            String optString = l.optString("white_error_code");
            if (!TextUtils.isEmpty(optString)) {
                try {
                    String[] split = optString.split(",");
                    if (split.length > 0) {
                        int[] iArr3 = new int[split.length];
                        while (i3 < split.length) {
                            iArr3[i3] = Integer.parseInt(split[i3]);
                            i3++;
                        }
                        iArr2 = iArr3;
                    }
                } catch (Throwable unused) {
                }
            }
            iArr = iArr2;
            i2 = i4;
            i4 = optInt;
            z = z2;
            optInt = optInt2;
        } else {
            iArr = null;
            i2 = 60;
            optInt = 60;
            z = false;
        }
        return new a(i, b, optInt, i4 * 1000, i2 * 1000, z, iArr);
    }

    public final int h() {
        try {
            if (this.g == null) {
                this.g = (ConnectivityManager) this.a.getApplicationContext().getSystemService("connectivity");
            }
            NetworkInfo activeNetworkInfo = this.g.getActiveNetworkInfo();
            if (activeNetworkInfo != null) {
                if (activeNetworkInfo.isConnected()) {
                    return activeNetworkInfo.getType() == 1 ? 2 : 1;
                }
            }
        } catch (Exception unused) {
        }
        return 0;
    }

    public boolean handleMessage(Message message) {
        if (message.what == 0) {
            c.j.a.d.b.e.b.q().execute(new y(this, message.arg1, message.arg2 == 1));
        } else {
            StringBuilder g = c.b.a.a.a.g("handleMessage, doSchedulerRetry, id = ");
            g.append(message.what);
            c.j.a.d.b.g.a.e("RetryScheduler", g.toString());
            c.j.a.d.b.e.b.q().execute(new z(this, message.what));
        }
        return true;
    }

    public void c() {
        b(3, false);
    }

    public void b() {
        b(4, false);
    }
}
